/*
 * Copyright 2020 lcnap
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package pers.lcnap.simplerpc.util;

import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import com.codahale.metrics.jmx.JmxReporter;

/**
 * 测量数据,通过JMX暴露数据
 */
public class MetricUtil {
    public final static MetricRegistry metricRegistry = new MetricRegistry();

    //请求处理时间
    public final static Timer rpcRequestSpendTime = metricRegistry.timer("rpc-request-spend-time");
    //客户端请求数
    public final static Meter rpcRequestSendCount = metricRegistry.meter("rpc-request-send-count");
    //JMS暴露数据
    private final static JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).build();

   /* private final static CsvReporter csvReporter = CsvReporter.forRegistry(metricRegistry)
            .formatFor(Locale.CHINA)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build(new File("/metric-data/"));*/

    static {
        reporter.start();
        // csvReporter.start(1, TimeUnit.SECONDS);
    }
}
